﻿using System;
using System.Xml;
using System.Xml.Serialization;
using System.Drawing;
using rlTodayMakeSkin.Project.Attributes;
using rlTodayMakeSkin.Project.XmlElement.XmlSubElements;
using System.Windows.Forms;

namespace rlTodayMakeSkin.Project.XmlElement
{
    /// <summary>
    /// represents a Date element in skin.xml file
    /// </summary>
    public class rlDate : ContainerSubElements
    {
        private string format="dd MM yyyy";
        private string align=Alignment.LEFT;
        private int timeZone = 0;
        private Color colore = Color.Black;

        private DateTime thisDate = DateTime.Now;

        public rlDate(XmlNode n, rlTodayProject p)
            : base(n, p)
        {
            if (listaAtt["format"] != null) format = listaAtt["format"].Value;
            if (listaAtt["alignment"] != null) align = listaAtt["alignment"].Value;
            if (listaAtt["timezone"] != null) align = listaAtt["timezone"].Value;
            font = new rlFont(this);
            strNome = "Date";
            
        }

        public rlDate(rlTodayProject p)
            : base(p)
        {
            font = new rlFont(this);
            strNome = "Date";
        }

        /// <summary>
        /// for the serialization
        /// </summary>
        public rlDate() { }

        /**********************
         PUBLIC MEMBERS
         ********************/
        /// <summary>
        /// Gets, sets date format value
        /// </summary>
        [PropertyDescription("Date format", PropertyTypes.DATE_FORMAT)]
        [XmlAttribute("format")]
        public string Format
        {
            get { return format; }
            set { format = value; }
        }

        /// <summary>
        /// Gets, sets text alignment value
        /// </summary>
        [PropertyDescription("Text alignment", PropertyTypes.ALIGNMENT)]
        [XmlAttribute("alignment")]
        public string Align
        {
            get { return align; }
            set { align = value; }
        }

        /// <summary>
        /// Gets, sets the number of the timezone used for this clock. Count starting 0, so timezone=“0” for the first timezone
        /// </summary>
        [PropertyDescription("The number of the timezone used for this date. Count starting 0, so timezone=\"0\" for the first timezone", PropertyTypes.INTEGER)]
        [XmlAttribute("timezone")]
        public int TimeZone
        {
            get { return timeZone; }
            set { timeZone = value; }
        }

        /// <summary>
        /// Gets a string that represents color in RGB format
        /// </summary>
        [PropertyDescription("string that represents color in RGB format", ReadOnlyProperty = true)]
        [XmlAttribute("color")]
        public string RGBColor
        {
            get { return GetRGBFromColor(colore); }
            set { /*required by the XmlSerializer*/}
        }

        /// <summary>
        /// Gets, sets text color of this element
        /// </summary>
        [PropertyDescription("text color of this element", PropertyTypes.COLOR)]
        [XmlIgnore()]
        public Color DateColor
        {
            get { return colore; }
            set { colore = value; }
        }

        public override void DrawElement(Graphics g)
        {
            DrawString(g, GetFormattedDate(format, thisDate), font, colore);
        }


        /**********************
         PRIVATE MEMBERS
         ********************/


    }
}
